package service.impl;

import dao.AdminDao;
import dao.impl.AdminDaoIpml;
import entity.Admin;
import service.AdminService;

import java.util.List;

public class AdminServiceImpl implements AdminService {
    AdminDao dao = new AdminDaoIpml();
    @Override
    public boolean addAdmin(Admin admin) {
        boolean exist = this.isExistById(admin.getId());
        if (exist){
            System.out.println("添加失败，此账号已存在！");
            return false;
        }else{
            System.out.println("添加成功！");
            return dao.addAdmin(admin) == 1;
        }
    }

    @Override
    public boolean updAdmin(Admin admin) {
        boolean exist = this.isExistById(admin.getId());
        if (exist){
            System.out.println("修改成功！");
            return dao.updAdmin(admin) == 1;
        }else{
            System.out.println("修改失败，此账号不存在！");
            return false;
        }
    }

    @Override
    public boolean delAdmin(Integer id) {
        boolean exist = this.isExistById(id);
        if(exist){
            System.out.println("删除成功！");
            return  dao.delAdminById(id) == 1;
        }else{
            System.out.println("删除失败，此账号不存在");
            return false;
        }
    }

    @Override
    public List<Admin> findAllAdmin() {
        return dao.findAllAdmin();
    }

    @Override
    public Admin findAdminById(Integer id) {
        return dao.findAdminById(id);
    }

    @Override
    public boolean isExistById(Integer id) {
        return false;
    }

    @Override
    public Admin login(String username, String password) {
        return dao.login(username,password);
    }
}